#!/usr/bin/perl
use strict;
use warnings;

open (TT, "./1.2-systeme_de_base.perl /home/icarius/Cours/EIT2/critiquesFilms/supervised |") || die $!;
open (OUT,">./1.0-resume.html")|| die $!;

print OUT "
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"fr\" xml:lang= \"fr\">
<head>
	<title>Compte rendu du la partie \"Syst&egrave;me de base\"</title>
</head>
<body>
";
######################
#   Classification   #
######################
my $tmp="";
my $stat=0;
my $ligne="";
while($tmp!~/^(.*)\t(.*)$/){
	$tmp=<TT>;
}
while($ligne!~/^(.*)\t(.*)$/){
	$ligne=<TT>;
}
if($ligne=~ /^(.*)\t(.*)$/){
print OUT "<h1 style=\"text-align:center;\">$2</h1>
	<hr>
	<h2>Classifieur Bay&eacute;sien na&iuml;f</h2>";
}
$ligne= $tmp;
if($ligne=~ /^(.*)\t(.*)$/){
print OUT "
	<table border=\"2\">
		<tr>
			<td colspan=2>
				<h4>Evalution sur $2 partitions<h4>
			</td>
		</tr>";
}



while ($ligne = <TT>){
	if($ligne=~ /^(.*)\t(.*)\t(.*)\t(.*)$/){
		print OUT "<tr><td style=\"width:50%\">Moyenne</td><td style=\"width:50%\">$2</td></tr>";
		print OUT "<table>";
		print OUT "Fait en $4</br>";
	}elsif($ligne=~ /^(.*)\t(.*)$/){
		if($stat==0){
			$stat=1;
			print OUT "<tr><td style=\"width:50%\">Eval sur $2</td>";
		}elsif($stat==1){
			$stat=0;
			print OUT "<td style=\"width:50%\">$2</td></tr>";
		}
	}
}
close TT;
print OUT "<hr>
	<h2>Description des classes</h2>";


#####################
#  Mots importants  #
#####################


open (TT, "./1.4-description_des_classes.perl ../critiquesFilms/supervised/ 10 |") || die $!;
$stat=0;
print OUT "
	<table border=\"2\">
		<tr><td rowspan=2>Nb &eacute;toiles</td><td colspan=10>Mots significatifs</td>
		<tr><td>1er</td><td>2ieme</td><td>3ieme</td><td>4ieme</td><td>5ieme</td><td>6ieme</td><td>7ieme</td><td>8ieme</td><td>9ieme</td><td>10ieme</td>";
while ($ligne = <TT>){
	if($ligne=~ /^(.*)\t(.*)$/){
		my $nb1=$1;
		my $val=$2;
		if($stat==1){
			if($nb1=~/^For class$/){
				print OUT "</tr><tr>"
			}
			if($nb1=~/Fait en/){
				print OUT "</tr>";
				print OUT "<table>";
				print OUT "Fait en $val</br>";
			}else{
				print OUT "<td>$val</td>";
			}
		}else{
			$stat=1;
		}
	}
}


print OUT "</body>";
system("firefox 1.0-resume.html &");
